package com.imc.platform.base.user.dao.repository;

import com.imc.platform.base.user.pojo.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by tanweiping on 2018/7/20.
 */
@Repository
public interface UserRepository extends JpaRepository<User, String>, JpaSpecificationExecutor<User> {

    User findAllByOpenId(String openId);


    User findFirstByOpenId(String openId);

    List<User> findAllById(String id);

    User findAllByLoginName(String loginName);
    User findFirstByLoginName(String loginName);

    User findAllByLoginNameAndOpenId(String loginName,String openId);

    User findUserById(Integer id);

    @Query(
            nativeQuery = true,
            value = "SELECT * FROM t_user WHERE id = :id"
    )
    User nativeFindAllById(@Param("id") String id);

//    @Query(
//            value = " SELECT u.* from t_order mOrder\n" +
//                    "  INNER JOIN t_user u ON mOrder.userId = u.id\n" +
//                    "  INNER JOIN t_order_detail odetail on mOrder.id = odetail.orderId\n" +
//                    "WHERE odetail.goodsId = #{lessonId}\n",
//            nativeQuery = true)
//    List<User> findAllByLessonId(@Param("lessonId")String lessonId);

}
